package com.bw.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.bw.domain.SysGw;
import com.bw.service.SysGwService;
import com.bw.utils.common.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author bobo棒
 * @date 2024年01月23日 14:04
 */

@RequestMapping("gw")
@RestController
public class GWController {
    @Autowired
    SysGwService sysGwService;


    @RequestMapping("list")
    public Result list(@RequestBody(required = false) SysGw sysGw,@RequestParam(defaultValue = "1") Integer pageNum){

        LambdaQueryWrapper<SysGw> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(ObjectUtils.isNotEmpty(sysGw.getBm()),SysGw::getBm,sysGw.getBm());
        queryWrapper.like(ObjectUtils.isNotEmpty(sysGw.getMc()),SysGw::getMc,sysGw.getMc());
        queryWrapper.eq(ObjectUtils.isNotEmpty(sysGw.getStatus()),SysGw::getStatus,sysGw.getStatus());
        PageHelper.startPage(pageNum,3);
        List<SysGw> list = sysGwService.list(queryWrapper);
        return Result.success(new PageInfo<>(list));
    }


    @RequestMapping("delById")
    public Result delById(Integer id){
        boolean b = sysGwService.removeById(id);
        return b?Result.success():Result.fail();
    }
}
